import Vue from "vue";
import VueRouter from "vue-router";

/* Layout */
import Layout from "../layout";

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "home",
        name: "Home",
        component: () => import("../views/Home"),
        meta: { title: "商品浏览", icon: "el-icon-s-home svg-icon" }
      }
    ]
  },
  {
    path: "/adminManage",
    component: Layout,
    redirect: "/adminManage/team",
    meta: { title: "管理员", icon: "el-icon-set-up svg-icon" },
    children: [
      {
        path: "team",
        name: "Team",
        component: () => import("../views/adminManage/team/index"),
        meta: { title: "组", icon: "el-icon-user-solid svg-icon" }
      },
      {
        path: "admin",
        name: "Admin", //管理员界面
        component: () => import("../views/adminManage/user/index"),
        meta: { title: "个人", icon: "el-icon-set-up svg-icon" }
      }
    ]
  },
  {
    path: "/customerManage",
    component: Layout,
    redirect: "/customerManage/customer",
    meta: { title: "用户管理", icon: "el-icon-set-up svg-icon" },
    children: [
      {
        path: "customer",
        name: "Customer", //用户界面
        component: () => import("@/views/customer/index"),
        meta: { title: "用户", icon: "el-icon-user svg-icon" }
      },
      {
        path: "transactLog",
        name: "TransactLog", //交易日志界面
        component: () => import("@/views/customer/transactLog/index"),
        meta: { title: "交易日志", icon: "el-icon-date" }
      }
    ]
  },
  {
    path: "/favoriteshopManage",
    component: Layout,
    redirect: "/favoriteshopManage/favorite",
    meta: { title: "收藏夹管理", icon: "el-icon-collection-tag" },
    children: [
      {
        path: "favorite",
        name: "Favorite",
        component: () => import("@/views/favoriteshopManage/favorite/index"),
        meta: { title: "收藏夹", icon: "el-icon-star-on" }
      }
    ]
  },
  {
    path: "/merchantservicesManage",
    component: Layout,
    redirect: "/merchantservicesManage/csstaff",

    children: [
      {
        path: "csstaff",
        name: "Csstaff",
        component: () =>
          import("../views/merchantservicesManage/csstaff/index"),
        meta: { title: "客服", icon: "el-icon-user-solid" }
      }
    ]
  },
  {
    path: "/shopcartManage",
    component: Layout,
    redirect: "/shopcartManage/shopcart",
    children: [
      {
        path: "shopcart",
        name: "Shopcart",
        component: () => import("../views/shopcartManage/index"),
        meta: { title: "购物车", icon: " el-icon-shopping-cart-2" }
      }
    ]
  },
  {
    path: "/warehousetManage",
    component: Layout,
    redirect: "/warehousetManage/gategory",
    meta: { title: "商品厂库管理", icon: "el-icon-s-home" },
    children: [
      {
        path: "gategory",
        name: "Gategory",
        component: () => import("../views/warehouseManage/gategory/index"),
        meta: { title: "商品种类", icon: " el-icon-s-home" }
      },
      {
        path: "product",
        name: "Product",
        component: () => import("../views/warehouseManage/product/index"),
        meta: { title: "商品", icon: " el-icon-s-grid" }
      }
    ]
  }
];

const createRouter = () =>
  new VueRouter({
    mode: "history", // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: routes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
